package com.yq.fileopen.dao.impl;

import com.yq.fileopen.dao.studentDao;
import com.yq.fileopen.model.Student;
import com.yq.fileopen.model.StudentData;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;


/**
 * @author 3307235355@qq.com
 * @since 2022/06/24 21:29
 */
public class StudentDaoImpl  implements studentDao {
    private static Student[] STUDS = StudentData.STUDS;
    @Override
    public boolean saveDataToFile() throws IOException {
        BufferedWriter out = new BufferedWriter(new FileWriter("students1.txt"));
        for (int i = 0; i < STUDS.length; i++) {
            if (STUDS[i]==null){
                continue;
            }
            out.write(String.valueOf(STUDS[i]));
            out.newLine();
        }
        out.close();
        return false;
    }

    public static void main(String[] args) throws IOException {
        // System.out.println(Arrays.toString(StudentDaoImpl.STUDS));
        // System.out.println(StudentDaoImpl.STUDS[0]);
        // System.out.println(StudentDaoImpl.STUDS[1]);
        System.out.println(StudentDaoImpl.STUDS[10]);

        StudentDaoImpl studentDao = new StudentDaoImpl();
        System.out.println(studentDao.saveDataToFile());
    }
}


    // public boolean saveDataToFile()  {
    //     BufferedWriter out = new BufferedWriter(new FileWriter("students1.txt"));
    //     for (int i = 0; i < STUDS.length; i++) {
    //         if (STUDS[i]==null){
    //             continue;
    //         }
    //         out.write(String.valueOf(STUDS[i]));
    //         out.newLine();
    //     }
    //     out.close();
    //     return false;
    // }